|
1
|
|
|
'use strict'; |
|
2
|
|
|
|
|
3
|
|
|
import * as fs from 'fs'; |
|
4
|
|
|
import * as path from 'path'; |
|
5
|
|
|
import { assert } from 'chai'; |
|
6
|
|
|
import Botlang from '../src/Botlang'; |
|
7
|
|
|
import pkg from '../package.json'; |
|
8
|
|
|
|
|
9
|
|
|
/** @test {Botlang} */ |
|
10
|
|
|
describe(`${pkg.name}/Botlang`, () => { |
|
11
|
|
|
/** @test {Botlang#constructor} */ |
|
12
|
|
|
describe('#constructor', () => { |
|
13
|
|
|
it('Create a new instance of type Botlang', () => { |
|
14
|
|
|
const sourceCode = fs.readFileSync(path.join(__dirname, 'Data', 'hello_world.bot'), { |
|
15
|
|
|
encoding : 'utf8', |
|
16
|
|
|
flag : 'r' |
|
17
|
|
|
}), |
|
18
|
|
|
botlang = new Botlang(sourceCode); |
|
19
|
|
|
|
|
20
|
|
|
assert.instanceOf(botlang, Botlang); |
|
21
|
|
|
}); |
|
22
|
|
|
}); |
|
23
|
|
|
|
|
24
|
|
|
/** @test {Botlang#reply} */ |
|
25
|
|
|
describe('#reply', () => { |
|
26
|
|
|
const sourceCode = fs.readFileSync(path.join(__dirname, 'Data', 'hello_world.bot'), { |
|
27
|
|
|
encoding : 'utf8', |
|
28
|
|
|
flag : 'r' |
|
29
|
|
|
}), |
|
30
|
|
|
botlang = new Botlang(sourceCode); |
|
31
|
|
|
|
|
32
|
|
|
it('Should return an empty string', () => { |
|
33
|
|
|
assert.match(botlang.reply(''), /^$/); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
it('Should return "Hi, how is it going?"', () => { |
|
37
|
|
|
assert.match(botlang.reply('Hey'), /Hi, how is it going?/); |
|
38
|
|
|
}); |
|
39
|
|
|
|
|
40
|
|
|
it('Should return "I think Botlang is freakin awesome!"', () => { |
|
41
|
|
|
assert.match(botlang.reply('What do you think about Botlang?'), /I think Botlang is freakin awesome!/); |
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
it('Should return "Hi, how are you?" or "Hey, how are you?"', () => { |
|
45
|
|
|
assert.match(botlang.reply('Hello there'), /Hi, how are you?|Hey, how are you?/); |
|
46
|
|
|
}); |
|
47
|
|
|
|
|
48
|
|
|
it('Should return "Sorry, I do not know the answer to that question."', () => { |
|
49
|
|
|
assert.match(botlang.reply('Yay ...'), /Sorry, I do not know the answer to that question./); |
|
50
|
|
|
}); |
|
51
|
|
|
}); |
|
52
|
|
|
|
|
53
|
|
|
/** @test {Botlang#version} */ |
|
54
|
|
|
describe('#version', () => { |
|
55
|
|
|
it('Should return the current version', () => { |
|
56
|
|
|
assert.equal(Botlang.version(), pkg.version); |
|
57
|
|
|
}); |
|
58
|
|
|
}); |
|
59
|
|
|
}); |
|
60
|
|
|
|